using System;
using System.Data;
using HRM.Common;
namespace HRM.BusinessLogic
{
    public class Employee_Info : Standard_Info
    {
        public Employee_Info()
        {
        }

        private int _Employee_ID;

        public int Employee_ID
        {
            get { return _Employee_ID; }
            set { _Employee_ID = value; }
        }

        private string _Employee_Code;

        public string Employee_Code
        {
            get { return _Employee_Code; }
            set { _Employee_Code = value; }
        }

        private string _Employee_CardNo;

        public string Employee_CardNo
        {
            get { return _Employee_CardNo; }
            set { _Employee_CardNo = value; }
        }

        private string _Employee_FirstName;

        public string Employee_FirstName
        {
            get { return _Employee_FirstName; }
            set { _Employee_FirstName = value; }
        }

        private string _Employee_LastName;

        public string Employee_LastName
        {
            get { return _Employee_LastName; }
            set { _Employee_LastName = value; }
        }

        private int _Employee_Education;

        public int Employee_Education
        {
            get { return _Employee_Education; }
            set { _Employee_Education = value; }
        }

        private string _Employee_Alias;

        public string Employee_Alias
        {
            get { return _Employee_Alias; }
            set { _Employee_Alias = value; }
        }

        private string _Employee_UserName;

        public string Employee_UserName
        {
            get { return _Employee_UserName; }
            set { _Employee_UserName = value; }
        }

        private DateTime _Employee_DateOfBirth;

        public DateTime Employee_DateOfBirth
        {
            get { return _Employee_DateOfBirth; }
            set { _Employee_DateOfBirth = value; }
        }

        private bool _Employee_Sex;

        public bool Employee_Sex
        {
            get { return _Employee_Sex; }
            set { _Employee_Sex = value; }
        }

        private int _Employee_MaterialStatusID;

        public int Employee_MaterialStatusID
        {
            get { return _Employee_MaterialStatusID; }
            set { _Employee_MaterialStatusID = value; }
        }

        private int _Employee_ReligionID;

        public int Employee_ReligionID
        {
            get { return _Employee_ReligionID; }
            set { _Employee_ReligionID = value; }
        }

        private int _Employee_EthlicID;

        public int Employee_EthlicID
        {
            get { return _Employee_EthlicID; }
            set { _Employee_EthlicID = value; }
        }

        private string _Employee_PlaceOfBirth;

        public string Employee_PlaceOfBirth
        {
            get { return _Employee_PlaceOfBirth; }
            set { _Employee_PlaceOfBirth = value; }
        }

        private string _Employee_Address;

        public string Employee_Address
        {
            get { return _Employee_Address; }
            set { _Employee_Address = value; }
        }
        private string _Employee_AddressLH;

        public string Employee_AddressLH
        {
            get { return _Employee_AddressLH; }
            set { _Employee_AddressLH = value; }
        }
        private string _Employee_AddressKS;

        public string Employee_AddressKS
        {
            get { return _Employee_AddressKS; }
            set { _Employee_AddressKS = value; }
        }

        private string _Employee_AddressHK;

        public string Employee_AddressHK
        {
            get { return _Employee_AddressHK; }
            set { _Employee_AddressHK = value; }
        }

        private string _Employee_NativeCountry;

        public string Employee_NativeCountry
        {
            get { return _Employee_NativeCountry; }
            set { _Employee_NativeCountry = value; }
        }

        private string _Employee_Phone;

        public string Employee_Phone
        {
            get { return _Employee_Phone; }
            set { _Employee_Phone = value; }
        }

        private string _Employee_Email;

        public string Employee_Email
        {
            get { return _Employee_Email; }
            set { _Employee_Email = value; }
        }

        private string _Employee_ChaMe;

        public string Employee_ChaMe
        {
            get { return _Employee_ChaMe; }
            set { _Employee_ChaMe = value; }
        }

        private string _Employee_ThanNhanKhac;

        public string Employee_ThanNhanKhac
        {
            get { return _Employee_ThanNhanKhac; }
            set { _Employee_ThanNhanKhac = value; }
        }
        private string _Employee_PassportNo;

        public string Employee_PassportNo
        {
            get { return _Employee_PassportNo; }
            set { _Employee_PassportNo = value; }
        }

        private DateTime _Employee_PassportIssueDate;

        public DateTime Employee_PassportIssueDate
        {
            get { return _Employee_PassportIssueDate; }
            set { _Employee_PassportIssueDate = value; }
        }

        private DateTime _Employee_PassportExpireDate;

        public DateTime Employee_PassportExpireDate
        {
            get { return _Employee_PassportExpireDate; }
            set { _Employee_PassportExpireDate = value; }
        }

        private int _Employee_Nationality;

        public int Employee_Nationality
        {
            get { return _Employee_Nationality; }
            set { _Employee_Nationality = value; }
        }

        private string _Employee_IDCardNo;

        public string Employee_IDCardNo
        {
            get { return _Employee_IDCardNo; }
            set { _Employee_IDCardNo = value; }
        }

        private DateTime _Employee_IDCardIssueDate;

        public DateTime Employee_IDCardIssueDate
        {
            get { return _Employee_IDCardIssueDate; }
            set { _Employee_IDCardIssueDate = value; }
        }

        private string _Employee_IDCardIssueAuthority;

        public string Employee_IDCardIssueAuthority
        {
            get { return _Employee_IDCardIssueAuthority; }
            set { _Employee_IDCardIssueAuthority = value; }
        }

        private string _Employee_SIBookNo;

        public string Employee_SIBookNo
        {
            get { return _Employee_SIBookNo; }
            set { _Employee_SIBookNo = value; }
        }

        private DateTime _Employee_SIBookIssueDate;

        public DateTime Employee_SIBookIssueDate
        {
            get { return _Employee_SIBookIssueDate; }
            set { _Employee_SIBookIssueDate = value; }
        }

        private string _Employee_SIBookIssueAuthority;

        public string Employee_SIBookIssueAuthority
        {
            get { return _Employee_SIBookIssueAuthority; }
            set { _Employee_SIBookIssueAuthority = value; }
        }

        private string _Employee_BankAccountNo;

        public string Employee_BankAccountNo
        {
            get { return _Employee_BankAccountNo; }
            set { _Employee_BankAccountNo = value; }
        }

        private string _Employee_BankName;

        public string Employee_BankName
        {
            get { return _Employee_BankName; }
            set { _Employee_BankName = value; }
        }

        private string _Employee_Description;

        public string Employee_Description
        {
            get { return _Employee_Description; }
            set { _Employee_Description = value; }
        }

        private bool _Employee_IsDelete;

        public bool Employee_IsDelete
        {
            get { return _Employee_IsDelete; }
            set { _Employee_IsDelete = value; }
        }

        private bool _Employee_IsQuited;

        public bool Employee_IsQuited
        {
            get { return _Employee_IsQuited; }
            set { _Employee_IsQuited = value; }
        }

        private DateTime _Employee_StartDate;

        public DateTime Employee_StartDate
        {
            get { return _Employee_StartDate; }
            set { _Employee_StartDate = value; }
        }

        private DateTime _Employee_EndDate;

        public DateTime Employee_EndDate
        {
            get { return _Employee_EndDate; }
            set { _Employee_EndDate = value; }
        }

        private int _EmployeeTotal;
        
        public int EmployeeTotal
        {
            get { return _EmployeeTotal; }
            set { _EmployeeTotal = value; }
        }
        private int _EmployeeMale;
        
        public int EmployeeMale
        {
            get { return _EmployeeMale; }
            set { _EmployeeMale = value; }
        }
        private int _EmployeeFemale;
        
        public int EmployeeFemale
        {
            get { return _EmployeeFemale; }
            set { _EmployeeFemale = value; }
        }
        private bool _Employee_IsOfficer;

        public bool Employee_IsOfficer
        {
            get { return _Employee_IsOfficer; }
            set { _Employee_IsOfficer = value; }
        }
        private string _Employee_MedicalNo;

        public string Employee_MedicalNo
        {
            get { return _Employee_MedicalNo; }
            set { _Employee_MedicalNo = value; }
        }
        private DateTime _Employee_MedicalDate;

        public DateTime Employee_MedicalDate
        {
            get { return _Employee_MedicalDate; }
            set { _Employee_MedicalDate = value; }
        }
        private string _Employee_MedicalPlace;

        public string Employee_MedicalPlace
        {
            get { return _Employee_MedicalPlace; }
            set { _Employee_MedicalPlace = value; }
        }

        private string _Employee_MedicalRegionCode;

        public string Employee_MedicalRegionCode
        {
            get { return _Employee_MedicalRegionCode; }
            set { _Employee_MedicalRegionCode = value; }
        }

        private bool _Employee_Type;

        public bool Employee_Type
        {
            get { return _Employee_Type; }
            set { _Employee_Type = value; }
        }
        private int _Employee_LeaveWorkID;

        public int Employee_LeaveWorkID
        {
            get { return _Employee_LeaveWorkID; }
            set { _Employee_LeaveWorkID = value; }
        }

        private bool _Employee_UnemployIns;

        public bool Employee_UnemployIns
        {
            get { return _Employee_UnemployIns; }
            set { _Employee_UnemployIns = value; }
        }

        private DateTime _Employee_UnemployInsDate;

        public DateTime Employee_UnemployInsDate
        {
            get { return _Employee_UnemployInsDate; }
            set { _Employee_UnemployInsDate = value; }
        }

        private string _Employee_Specialist;

        public string Employee_Specialist
        {
            get { return _Employee_Specialist; }
            set { _Employee_Specialist = value; }
        }
        private string _Employee_Culture;

        public string Employee_Culture
        {
            get { return _Employee_Culture; }
            set { _Employee_Culture = value; }
        }
        private bool _Employee_IsInitial;

        public bool Employee_IsInitial
        {
            get { return _Employee_IsInitial; }
            set { _Employee_IsInitial = value; }
        }
        private DateTime _Employee_PartyDate;

        public DateTime Employee_PartyDate
        {
            get { return _Employee_PartyDate; }
            set { _Employee_PartyDate = value; }
        }
        private DateTime _Employee_ArmyFromDate;

        public DateTime Employee_ArmyFromDate
        {
            get { return _Employee_ArmyFromDate; }
            set { _Employee_ArmyFromDate = value; }
        }
        private DateTime _Employee_ArmyToDate;

        public DateTime Employee_ArmyToDate
        {
            get { return _Employee_ArmyToDate; }
            set { _Employee_ArmyToDate = value; }
        }
        private string _Employee_ArmyPosition;

        public string Employee_ArmyPosition
        {
            get { return _Employee_ArmyPosition; }
            set { _Employee_ArmyPosition = value; }
        }
        private int _Employee_BranchID;

        public int Employee_BranchID
        {
            get { return _Employee_BranchID; }
            set { _Employee_BranchID = value; }
        }

        private bool _Employee_UnJobFactor;

        public bool Employee_UnJobFactor
        {
            get { return _Employee_UnJobFactor; }
            set { _Employee_UnJobFactor = value; }
        }

        private bool _Employee_UnOverFactor;

        public bool Employee_UnOverFactor
        {
            get { return _Employee_UnOverFactor; }
            set { _Employee_UnOverFactor = value; }
        }
        private string _Employee_PhuongThucBHTN;

        public string Employee_PhuongThucBHTN
        {
            get { return _Employee_PhuongThucBHTN; }
            set { _Employee_PhuongThucBHTN = value; }
        }
        private decimal _Employee_ThuNhapBHTN;

        public decimal Employee_ThuNhapBHTN
        {
            get { return _Employee_ThuNhapBHTN; }
            set { _Employee_ThuNhapBHTN = value; }
        }
        private string _Employee_PhuongThucBHYT;

        public string Employee_PhuongThucBHYT
        {
            get { return _Employee_PhuongThucBHYT; }
            set { _Employee_PhuongThucBHYT = value; }
        }
        private decimal _Employee_MucTienBHYT;

        public decimal Employee_MucTienBHYT
        {
            get { return _Employee_MucTienBHYT; }
            set { _Employee_MucTienBHYT = value; }
        }
        private string _Employee_DoiTuongBHYT;

        public string Employee_DoiTuongBHYT
        {
            get { return _Employee_DoiTuongBHYT; }
            set { _Employee_DoiTuongBHYT = value; }
        }
    }

    public class Employee_Controller : Standard_Controller
    {
        #region "Contructor"
        private static Employee_Controller _instance;
        protected Employee_Controller() { }
        protected new void Dispose()
        {
            _instance = null;
        }
        private static object _syncLock = new object();
        public static Employee_Controller Instance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                        _instance = new Employee_Controller();
                }
            }
            return _instance;
        }
        public static Employee_Controller Instance(String transName)
        {
            if (!String.IsNullOrEmpty(transName))
            {
                Employee_Controller _instanceTrans = new Employee_Controller();
                _instanceTrans.Trans_Name = transName;
                return _instanceTrans;
            }
            else
                return Instance();
        }
        #endregion

        public const String cs_Table_Name = "";
        public DataTable Employee_DSChuDanh(string branchCode, String keyword, Int32 department_Id, Int32 year)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_DSChucDanh", false)
                , branchCode
                , keyword
                , department_Id
                , year
                ).Tables[0];
        }

        public DataTable Employee_DSChuDanh(string branchCode, Int32 department_Id, String keyword, Int32 year, Int32 type)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_DSChucDanh", false)
                , branchCode
                , department_Id
                , keyword
                , year
                , type).Tables[0];
        }
        public void Employee_UpdateChucDanh(Int32 Detail_Id,String BranchCode, String Detail_InsBookNo, DateTime From_Date, DateTime To_Date, String chucDanh)
        {
            DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_UpdateChucDanh", false)
                , Detail_Id
                , BranchCode
                , Detail_InsBookNo
                , From_Date
                , To_Date
                , chucDanh);
        }
        public void Employee_DeleteChucDanh(Int32 Detail_Id)
        {
            DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_DeleteChucDanh", false)
                , Detail_Id);
        }
        public DataTable Employee_DieuChinhLuongTheoNhom(string branchCode, Int32 department_Id, Int32 year, Int32 month, float Amount)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_DieuChinhLuongTheoNhom", false)
                , branchCode
                , department_Id
                , year
                , month
                , Convert.ToDecimal(Amount)).Tables[0];
        }
        public DataTable Employee_QuaTrinhChucDanh(string SoSo, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_QuaTrinhChucDanh", false)
                , SoSo
                , BranchCode).Tables[0];
        }
        public int Employee_InsertNS(Employee_Info eInfo)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_InsertNS"),
                eInfo.Employee_SIBookNo,
                eInfo.Employee_Sex,
                eInfo.Employee_BranchID,
                eInfo.Employee_FirstName,
                eInfo.Employee_LastName,
                eInfo.Employee_DateOfBirth,
                eInfo.Employee_EthlicID,
                eInfo.Employee_Nationality,
                eInfo.Employee_Phone,
                eInfo.Employee_Email,
                eInfo.Employee_IDCardNo,
                eInfo.Employee_IDCardIssueDate,
                eInfo.Employee_IDCardIssueAuthority,
                eInfo.Employee_MedicalNo,
                eInfo.Employee_MedicalRegionCode,
                eInfo.Employee_MedicalPlace,
                eInfo.Employee_ChaMe,
                eInfo.Employee_ThanNhanKhac,
                eInfo.Employee_AddressKS,
                eInfo.Employee_AddressHK,
                eInfo.Employee_AddressLH,
                eInfo.Employee_UnJobFactor,
                Globals.DB_GetNull(eInfo.Employee_UnOverFactor,0),
                eInfo.Employee_IsQuited,
                Globals.DB_GetNull(eInfo.Employee_ThuNhapBHTN,0),
                eInfo.Employee_PhuongThucBHTN,
                eInfo.Employee_DoiTuongBHYT,
                Globals.DB_GetNull( eInfo.Employee_MucTienBHYT,0),
                eInfo.Employee_PhuongThucBHYT));
        }
        public bool Employee_UpdateNS(Employee_Info eInfo)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_UpdateNS"),
                eInfo.Employee_ID,
                eInfo.Employee_SIBookNo,
                eInfo.Employee_Sex,
                eInfo.Employee_BranchID,
                eInfo.Employee_FirstName,
                eInfo.Employee_LastName,
                eInfo.Employee_DateOfBirth,
                eInfo.Employee_EthlicID,
                eInfo.Employee_Nationality,
                eInfo.Employee_Phone,
                eInfo.Employee_Email,
                eInfo.Employee_IDCardNo,
                eInfo.Employee_IDCardIssueDate,
                eInfo.Employee_IDCardIssueAuthority,
                eInfo.Employee_MedicalNo,
                eInfo.Employee_MedicalRegionCode,
                eInfo.Employee_MedicalPlace,
                eInfo.Employee_ChaMe,
                eInfo.Employee_ThanNhanKhac,
                eInfo.Employee_AddressKS,
                eInfo.Employee_AddressHK,
                eInfo.Employee_AddressLH,
                eInfo.Employee_UnJobFactor,
                eInfo.Employee_UnOverFactor,
                eInfo.Employee_IsQuited,
                eInfo.Employee_ThuNhapBHTN,
                eInfo.Employee_PhuongThucBHTN,
                eInfo.Employee_DoiTuongBHYT,
                Globals.DB_GetNull(eInfo.Employee_MucTienBHYT,0),
                eInfo.Employee_PhuongThucBHYT) > 0);
        }

        public Employee_Info Employee_GetInfoBySIBookNo(string _SIBookNo, int _BranchId)
        {
            return CBO.FillObject<Employee_Info>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_GetInfoBySIBookNoAndBranch"), _SIBookNo, _BranchId));
        }

        public DataSet Employee_GetList(string _OrderBy, string _OrderDirection, int BranchID, int currPage, int pageSize, out int itemCount)
        {
            itemCount = 0;
            DataSet ds = DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_GetListNS", false), _OrderBy, _OrderDirection, BranchID, currPage, pageSize);

            //DataSet ds = DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_PositionDetail_GetForInsurance", false), DateTime.Now, BranchID, 0, "");

            if (ds != null && ds.Tables.Count > 0)
                itemCount = Globals.Object_GetValue<int>(ds.Tables[0].Rows.Count);
            return ds;

        }

        public DataTable Employee_GetOne(int Employee_ID)
        {
            DataTable dt = DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_GetOne", false), Employee_ID).Tables[0];
            return dt;
        }

        public DataTable Employee_GetReport(string Employee_ID)
        {
            DataTable dt = DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_GetReport", false), Employee_ID).Tables[0];
            return dt;
        }

        public Employee_Info Employee_GetInfo(int EmployeeID)
        {
            return CBO.FillObject<Employee_Info>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_GetInfo"), EmployeeID));
        }

        public bool CapNhatSoTheBHYT(int maDonVi, string soSoBHXH, string sokcb, string maTinh, string maBV)
        {
            return DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_CapNhatSoTheBHYT", false)
                , maDonVi
                , soSoBHXH
                , sokcb
                , maTinh
                , maBV
                ) > 0;
        }

        public void Employee_On(string SiBookNo, int BranchId)
        {
            DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_On", false)
                ,SiBookNo
                , BranchId);
        }

        public DataTable Employee_DSChuDanhExcel(string branchCode, DateTime fromDate, DateTime toDate)
        {
            return DataConnect.ExecuteTable(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_DSChucDanhExcel", false)
               , branchCode
               , fromDate
               ,toDate
            );
        }

        public int Import_ChucVu(string chucVu, string branchCode)
        {
           return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_ImportChucVu", false)
                , chucVu, branchCode));
        }

        public int Import_PhongBan(string phongBan, int branchId)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_ImportPhongBan", false)
                , phongBan, branchId));
        }
    }
}
